package com.becca.cake.model.users;

import java.io.Serializable;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;

/**
 * 用户实体
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年4月10日 上午11:15:31
 */
public class UsersModel implements Serializable {
    /**  */
    private static final long  serialVersionUID        = 8199663204871318189L;
    /**用户状态(0:可用  )*/
    public static final byte   USER_STATUS_USABLE      = 0;
    /**用户类型(2:试吃用户  )*/
    public static final byte   USER_TYPE_APPLY_EAT     = 2;

    /**手机号不能为空*/
    public static final String MOBILE_IS_NULL          = "手机号不能为空";
    /**该手机号已注册*/
    public static final String MOBILE_ALREADY_REGIST   = "该手机号已注册";
    /**密码不能为空*/
    public static final String PASSWORD_IS_NULL        = "密码不能为空";
    /**确认密码不能为空*/
    public static final String PASSWORD_TRUE_IS_NULL   = "确认密码不能为空";
    /**验证码不能为空*/
    public static final String VALIDATECODE_IS_NULL    = "验证码不能为空";
    /** 密码不一样校验 */
    public static final String PASSWORD_NOT_SAME       = "两次输入的密码不一致";
    /**验证码不存在或以过期 */
    public static final String VALIDATECODE_NOT_EXISTE = "验证码不存在或已过期";
    /**生日日期不能为空*/
    public static final String BIRTHDAY_IS_NULL        = "生日日期不能为空";
    /**生日不能为空*/
    public static final String SEX_IS_NULL             = "性别不能为空";
    /**登录成功*/
    public static final String USER_LOGIN_SUCCESS      = "登录成功";
    /** 用户不存在 */
    public static final String USER_NOT_EXIST          = "用户不存在";

    /** 用户密码错误 */
    public static final String USER_PWD_ERROR          = "密码错误";
    /** 修改成功 */
    public static final String USER_UPDATE_SUCCESS     = "修改成功";

    /** 修改成功 */
    public static final String USER_DEFAULT_PASSWORD   = "123456";

    /**该用户已设置为启用*/
    public static final String FIXING_STATUS_EXIST     = "该用户已设置为启用";

    /**该用户已设为禁用*/
    public static final String FIXING_NOT_STATUS_EXIST = "该用户已设为禁用";

    /**该用户编号为空*/
    public static final String USER_ID_NULL            = "该用户编号为空";

    /**用户类型不能为空*/
    public static final String USER_TYPE_NULL          = "用户类型不能为空";

    /**手机号可用！*/
    public static final String MOBILE_COULD_USER       = "手机号可用！";

    /**图片上传失败！*/
    public static final String PICTURE_UPLAOD_FAIL     = "图片上传失败！";

    private Integer            id;
    /**用户名*/
    private String             userName;
    /**真实姓名*/
    private String             trueName;
    /**用户登录手机号*/
    private String             mobileNo;
    /**用户密码*/
    private String             password;
    /**用户头像*/
    private String             headPic;
    /**邮箱*/
    private String             email;
    /**性别(0:男 1:女)*/
    private Byte               sex;
    /**用户类型(0:普通用户 1:企业用户 2:试吃用户)*/
    private Byte               userType;
    /**生日*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date               birthday;
    /**用户状态(0:可用  1:禁用)*/
    private Byte               status;
    /**生日修改次数*/
    private Integer            birthdayUpdateTimes;
    /**微信用户唯一标识*/
    private String             wechatOpenid;
    /**用户登录token*/
    private String             userToken;
    /**创建时间*/
    private Date               createdDate;
    /**创建人*/
    private String             createdName;
    /**修改时间*/
    private Date               updatedDate;
    /**修改人*/
    private String             updatedName;

    /****************************新加*******************************/
    private Integer            couponNum;

    /**统计用户数*/
    private Integer            userNum;
    /**生日*/
    private String             createUserDate;

    /**
     * 校验添加跟修改用户
     * @param usersModel
     * @param files
     */
    public static void validateAddOrUpdateParam(UsersModel usersModel, MultipartFile files) {
        if (StringUtils.isEmpty(usersModel.getMobileNo())) {
            throw new ServiceException(UsersModel.MOBILE_IS_NULL);
        }
        if (usersModel.getSex() == null) {
            throw new ServiceException(UsersModel.SEX_IS_NULL);
        }
        if (usersModel.getUserType() == null) {
            throw new ServiceException(UsersModel.USER_TYPE_NULL);
        }
    }

    /**
     * 校验该手机号的用户是否存在
     * @param userModel
     */
    public static void validMobileNo(UsersModel userModel) {
        if (userModel == null) {
            throw new ServiceException(UsersModel.USER_NOT_EXIST);
        }
    }

    /**
     * 用户ID为空
     * @param userId
     */
    public static void validUserIDNull(Integer userId) {
        if (userId == null) {
            throw new ServiceException(UsersModel.USER_ID_NULL);
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getTrueName() {
        return trueName;
    }

    public void setTrueName(String trueName) {
        this.trueName = trueName;
    }

    public String getMobileNo() {
        return mobileNo;
    }

    public void setMobileNo(String mobileNo) {
        this.mobileNo = mobileNo;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getHeadPic() {
        return headPic;
    }

    public void setHeadPic(String headPic) {
        this.headPic = headPic;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Byte getSex() {
        return sex;
    }

    public void setSex(Byte sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public Integer getBirthdayUpdateTimes() {
        return birthdayUpdateTimes;
    }

    public void setBirthdayUpdateTimes(Integer birthdayUpdateTimes) {
        this.birthdayUpdateTimes = birthdayUpdateTimes;
    }

    public String getWechatOpenid() {
        return wechatOpenid;
    }

    public void setWechatOpenid(String wechatOpenid) {
        this.wechatOpenid = wechatOpenid;
    }

    public String getUserToken() {
        return userToken;
    }

    public void setUserToken(String userToken) {
        this.userToken = userToken;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getUpdatedName() {
        return updatedName;
    }

    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }

    public Integer getCouponNum() {
        return couponNum;
    }

    public void setCouponNum(Integer couponNum) {
        this.couponNum = couponNum;
    }

    public Integer getUserNum() {
        return userNum;
    }

    public void setUserNum(Integer userNum) {
        this.userNum = userNum;
    }

    public Byte getUserType() {
        return userType;
    }

    public void setUserType(Byte userType) {
        this.userType = userType;
    }

    public String getCreateUserDate() {
        return createUserDate;
    }

    public void setCreateUserDate(String createUserDate) {
        this.createUserDate = createUserDate;
    }

    @Override
    public String toString() {
        return "UsersDO [id=" + id + ", userName=" + userName + ", trueName=" + trueName
               + ", mobileNo=" + mobileNo + ", password=" + password + ", headPic=" + headPic
               + ", email=" + email + ", sex=" + sex + ", birthday=" + birthday + ", status="
               + status + ", birthdayUpdateTimes=" + birthdayUpdateTimes + ", wechatOpenid="
               + wechatOpenid + ", userToken=" + userToken + ", createdDate=" + createdDate
               + ", createdName=" + createdName + ", updatedDate=" + updatedDate + ", updatedName="
               + updatedName + "]";
    }

}
